class Admin::RolesController < ApplicationController
  before_filter :login_required

  layout "admin"

  require_role ["admin"]

  def index
    if current_user.has_role?("admin")
      @roles = Role.find(:all)
    else
      @roles = Role.find(:all, :conditions => ["name != ?", "admin"])
    end

    respond_to do |format|
      format.html # index.html.erb
      #format.xml  { render :xml => @roles }
    end

  end

  def new
    @role = Role.new

    respond_to do |format|
      format.html # new.html.erb
      #format.xml  { render :xml => @role }
    end

  end

  def create
    @role = Role.new(params[:role])
    if @role.save
      redirect_to admin_roles_url
      flash[:notice] = "Successfully created role."
    else
      render :action => 'new'
    end

  end

  def destroy
    @role = Role.find(params[:id])
    @role.destroy

    respond_to do |format|
      format.html { redirect_to(admin_roles_url) }
      #format.xml  { head :ok }
    end

  end

end
